﻿namespace CSharpPro._1013;

public class Demo
{
    //作业1:键盘输入三个整数x、y、z，请把这三个数由小到大输出
    public void TestPrint1()
    {
        Console.WriteLine("请输入第一个整数x：");
        int x = Convert.ToInt32(Console.ReadLine());
        Console.WriteLine("请输入第二个整数y：");
        int y = Convert.ToInt32(Console.ReadLine());
        Console.WriteLine("请输入第三个整数z：");
        int z = Convert.ToInt32(Console.ReadLine());
        int temp;
        if (x > y)
        {
            temp = x;
            x = y;
            y = temp;
        }
        if (x > z)
        {
            temp = x;
            x = z;
            z = temp;
        }
        if (y > z)
        {
            temp = y;
            y = z;
            z = temp;
        }
        Console.WriteLine("三个数由小到大输出为：{0} {1} {2}", x, y, z);
    }
    //作业2:打印出1-100之间所有不是7的倍数和不包含7的数字,并求和
    public void TestPrint2()
    {
        int sum = 0;
        for (int i = 1; i <= 100; i++)
        {
            if (i % 7 != 0 && !i.ToString().Contains("7"))
            {
                Console.Write(i + " ");
                sum += i;
            }
        }
        Console.WriteLine($"\n和为：{sum}");
    }
    //作业3:打印九九乘法表
    public void TestPrint3()
    {
        for (int i = 1; i <= 9; i++)
        {
            for (int j = 1; j <= i; j++)
            {
                Console.Write($"{j}*{i}={i * j}\t");
            }
            Console.WriteLine();
        }
    }
    //作业4:求出1000以内的所有完数
    public void TestPrint4()
    {
        for (int i = 1; i < 1000; i++)
        {
            int sum = 0;
            for (int j = 1; j < i; j++)
            {
                if (i % j == 0) sum += j;
            }
            if (sum == i) Console.Write(i + " ");
        }
        Console.WriteLine();
    }
    //作业5:键盘录入一个正整数，请求：1.它是几位数？2.逆序打印出各位数字
    public void TestPrint5()
    {
        Console.WriteLine("请输入正整数：");
        string s = Console.ReadLine();
        Console.WriteLine($"是{ s.Length }位数");
        Console.Write("逆序：");
        for (int i = s.Length - 1; i >= 0; i--)
        {
            Console.Write(s[i]);
        }
        Console.WriteLine();
    }
    //作业6:打印菱形，根据输入的行数，显示菱形形状
    public void TestPrint6()
    {
        Console.WriteLine("请输入菱形的行数:");
        int rows = int.Parse(Console.ReadLine());
        int mid = rows / 2 + 1;
        for (int i = 1; i <= rows; i++)
        {
            int space = Math.Abs(i - mid);
            for (int j = 0; j < space; j++) Console.Write(" ");
            for (int j = 0; j < rows - 2 * space; j++) Console.Write("*");
            Console.WriteLine();
        }
    }
}